package com.qc.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.qc.dao.SysTemDao;
import com.qc.entity.SystemEntity;

@Repository("sysTemDao")
public class SysTemDaoImpl implements SysTemDao{


    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;
    
    @Override
    public SystemEntity getSysTem(String userName, String password) {
        String sql = "select user_name,password,nickName from t_system where 1 = 1 and user_name = '"+userName+"' and password = '"+password+"' ";
        
        SystemEntity systemEntity = new SystemEntity();
        jdbcTemplate.query(sql, new RowMapper<SystemEntity>() {
            public SystemEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
                systemEntity.setUserName(rs.getString("user_name"));
                systemEntity.setPassword(rs.getString("password"));
                systemEntity.setNickName(rs.getString("nickName"));
                
                return systemEntity;
            }
        });
        
        return systemEntity;
    }

}
